function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function e(t, e, n) {
    return e in t ? Object.defineProperty(t, e, {
        value: n,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = n, t;
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var n = t(require("../../utils/util")), i = t(require("../component")), o = {};

exports.default = {
    setDefaults: function() {
        return {
            title: "",
            content: "",
            buttons: []
        };
    },
    data: function() {
        return {
            cancelText: "取消",
            cancelType: "weui-dialog__btn_default",
            confirmText: "确定",
            confirmType: "weui-dialog__btn_primary",
            onCancel: function() {},
            onConfirm: function() {}
        };
    },
    open: function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, a = n.default.extend({
            visible: !1
        }, this.setDefaults(), t), r = t.scope || "wx.dialog";
        o[r] = getCurrentPages()[getCurrentPages().length - 1];
        var c = new i.default(o[r], {
            scope: r,
            data: a,
            methods: {
                hide: function(t) {
                    if (this.removed) return !1;
                    this.removed = !0, this.setHidden(), setTimeout(function() {
                        return "function" == typeof t && t();
                    }, 300);
                },
                show: function() {
                    if (this.removed) return !1;
                    a.reg && this.page.setData(e({}, r + ".btn_disabled", !0)), this.setVisible();
                },
                buttonTapped: function(t) {
                    var e = t.currentTarget.dataset.index, n = a.buttons[e];
                    "function" == typeof n.onTap && void 0 === n.onTap(t) && this.hide();
                },
                bindinput: function(t) {
                    var n, i = (t.detail.value || "").trim(), o = this.checkReg(i);
                    this.page.setData((n = {}, e(n, r + ".content", i), e(n, r + ".btn_disabled", !!o), 
                    n));
                },
                checkReg: function(t) {
                    var i = void 0;
                    if ("digit" === a.type) {
                        var o = (t = n.default.formatDecimal(t)).indexOf(".");
                        o = o > a.maxlength ? a.maxlength : o, this.page.setData(e({}, r + ".maxlength", o > -1 ? o + 1 + a.toFixed : a.maxlength));
                    } else this.page.setData(e({}, r + ".maxlength", a.maxlength));
                    return "function" == typeof a.reg ? i = a.reg(t) : "[object RegExp]" === Object.prototype.toString.call(a.reg) && (i = a.reg.test(t)), 
                    i;
                },
                onScroll: function(t) {
                    return !1;
                }
            }
        });
        return c.show(), c.hide;
    },
    comment: function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
        return this.open(n.default.extend({
            buttons: [ {
                text: t.cancelText || this.data().cancelText,
                type: t.cancelType || this.data().cancelType,
                onTap: function(e) {
                    "function" == typeof t.onCancel && t.onCancel(e);
                }
            }, {
                text: t.confirmText || this.data().confirmText,
                type: t.confrimType || this.data().confrimType,
                onTap: function(e) {
                    return "function" == typeof t.onConfirm && t.onConfirm(e);
                }
            } ],
            type: "textarea"
        }, t));
    },
    prompt: function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
        return this.open(n.default.extend({
            buttons: [ {
                text: t.cancelText || this.data().cancelText,
                type: t.cancelType || this.data().cancelType,
                name: "cancel",
                onTap: function(e) {
                    "function" == typeof t.onCancel && t.onCancel(e);
                }
            }, {
                text: t.confirmText || this.data().confirmText,
                type: t.confirmType || this.data().confirmType,
                name: "confirm",
                onTap: function(e) {
                    return "function" == typeof t.onConfirm && t.onConfirm(e);
                }
            } ],
            type: "text",
            toFixed: 2,
            maxlength: 7
        }, t));
    }
};